<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">-- -----------------------------------------------------------------------------</span><span>
</span><span id="line-2"></span><span class="hs-comment">--</span><span>
</span><span id="line-3"></span><span class="hs-comment">-- (c) The University of Glasgow 2012</span><span>
</span><span id="line-4"></span><span class="hs-comment">--</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- -----------------------------------------------------------------------------</span><span>
</span><span id="line-6"></span><span>
</span><span id="line-7"></span><span class="hs-comment">-- | Monadic streams</span><span>
</span><span id="line-8"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Data.Stream</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-9"></span><span>    </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier">Stream</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#yield"><span class="hs-identifier">yield</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#liftIO"><span class="hs-identifier">liftIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-10"></span><span>    </span><span class="annot"><a href="GHC.Data.Stream.html#collect"><span class="hs-identifier">collect</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#collect_"><span class="hs-identifier">collect_</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#consume"><span class="hs-identifier">consume</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#fromList"><span class="hs-identifier">fromList</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-11"></span><span>    </span><span class="annot"><a href="GHC.Data.Stream.html#map"><span class="hs-identifier">map</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#mapM"><span class="hs-identifier">mapM</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#mapAccumL"><span class="hs-identifier">mapAccumL</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#mapAccumL_"><span class="hs-identifier">mapAccumL_</span></a></span><span>
</span><span id="line-12"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-13"></span><span>
</span><span id="line-14"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span> </span><span class="hs-keyword">hiding</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier">map</span></a></span><span class="hs-special">,</span><span class="annot"><a href="../../base/src/Data.Traversable.html#mapM"><span class="hs-identifier">mapM</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-15"></span><span>
</span><span id="line-16"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Monad.html#"><span class="hs-identifier">Control.Monad</span></a></span><span> </span><span class="hs-keyword">hiding</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Data.Traversable.html#mapM"><span class="hs-identifier">mapM</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-17"></span><span>
</span><span id="line-18"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- @Stream m a b@ is a computation in some Monad @m@ that delivers a sequence</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- of elements of type @a@ followed by a result of type @b@.</span><span>
</span><span id="line-21"></span><span class="hs-comment">--</span><span>
</span><span id="line-22"></span><span class="hs-comment">-- More concretely, a value of type @Stream m a b@ can be run using @runStream@</span><span>
</span><span id="line-23"></span><span class="hs-comment">-- in the Monad @m@, and it delivers either</span><span>
</span><span id="line-24"></span><span class="hs-comment">--</span><span>
</span><span id="line-25"></span><span class="hs-comment">--  * the final result: @Left b@, or</span><span>
</span><span id="line-26"></span><span class="hs-comment">--  * @Right (a,str)@, where @a@ is the next element in the stream, and @str@</span><span>
</span><span id="line-27"></span><span class="hs-comment">--    is a computation to get the rest of the stream.</span><span>
</span><span id="line-28"></span><span class="hs-comment">--</span><span>
</span><span id="line-29"></span><span class="hs-comment">-- Stream is itself a Monad, and provides an operation 'yield' that</span><span>
</span><span id="line-30"></span><span class="hs-comment">-- produces a new element of the stream.  This makes it convenient to turn</span><span>
</span><span id="line-31"></span><span class="hs-comment">-- existing monadic computations into streams.</span><span>
</span><span id="line-32"></span><span class="hs-comment">--</span><span>
</span><span id="line-33"></span><span class="hs-comment">-- The idea is that Stream is useful for making a monadic computation</span><span>
</span><span id="line-34"></span><span class="hs-comment">-- that produces values from time to time.  This can be used for</span><span>
</span><span id="line-35"></span><span class="hs-comment">-- knitting together two complex monadic operations, so that the</span><span>
</span><span id="line-36"></span><span class="hs-comment">-- producer does not have to produce all its values before the</span><span>
</span><span id="line-37"></span><span class="hs-comment">-- consumer starts consuming them.  We make the producer into a</span><span>
</span><span id="line-38"></span><span class="hs-comment">-- Stream, and the consumer pulls on the stream each time it wants a</span><span>
</span><span id="line-39"></span><span class="hs-comment">-- new value.</span><span>
</span><span id="line-40"></span><span class="hs-comment">--</span><span>
</span><span id="line-41"></span><span class="hs-keyword">newtype</span><span> </span><span id="Stream"><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-var">Stream</span></a></span></span><span> </span><span id="local-6989586621680774262"><span class="annot"><a href="#local-6989586621680774262"><span class="hs-identifier hs-type">m</span></a></span></span><span> </span><span id="local-6989586621680774261"><span class="annot"><a href="#local-6989586621680774261"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span id="local-6989586621680774260"><span class="annot"><a href="#local-6989586621680774260"><span class="hs-identifier hs-type">b</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="Stream"><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-var">Stream</span></a></span></span><span> </span><span class="hs-special">{</span><span> </span><span id="runStream"><span class="annot"><span class="annottext">forall (m :: * -&gt; *) a b.
Stream m a b -&gt; m (Either b (a, Stream m a b))
</span><a href="GHC.Data.Stream.html#runStream"><span class="hs-identifier hs-var hs-var">runStream</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621680774262"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774260"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680774261"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774262"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774261"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774260"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-42"></span><span>
</span><span id="line-43"></span><span id="local-6989586621680774250"><span id="local-6989586621680774251"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680774107"><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774251"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Functor"><span class="hs-identifier hs-type">Functor</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774251"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774250"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-44"></span><span>  </span><span id="local-6989586621680774104"><span class="annot"><span class="annottext">fmap :: forall a b. (a -&gt; b) -&gt; Stream f a a -&gt; Stream f a b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var hs-var hs-var hs-var">fmap</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(a -&gt; b) -&gt; Stream f a a -&gt; Stream f a b
forall (m :: * -&gt; *) a1 r. Monad m =&gt; (a1 -&gt; r) -&gt; m a1 -&gt; m r
</span><a href="../../base/src/GHC.Base.html#liftM"><span class="hs-identifier hs-var">liftM</span></a></span></span></span><span>
</span><span id="line-45"></span><span>
</span><span id="line-46"></span><span id="local-6989586621680774230"><span id="local-6989586621680774231"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680774093"><span id="local-6989586621680774095"><span id="local-6989586621680774097"><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774231"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Applicative"><span class="hs-identifier hs-type">Applicative</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774231"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774230"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-47"></span><span>  </span><span id="local-6989586621680774090"><span class="annot"><span class="annottext">pure :: forall a. a -&gt; Stream m a a
</span><a href="../../base/src/GHC.Base.html#pure"><span class="hs-identifier hs-var hs-var hs-var hs-var">pure</span></a></span></span><span> </span><span id="local-6989586621680774089"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774089"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">m (Either a (a, Stream m a a)) -&gt; Stream m a a
forall (m :: * -&gt; *) a b.
m (Either b (a, Stream m a b)) -&gt; Stream m a b
</span><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-var">Stream</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Either a (a, Stream m a a) -&gt; m (Either a (a, Stream m a a))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Either a (a, Stream m a a)
forall a b. a -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774089"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-48"></span><span>  </span><span id="local-6989586621680774087"><span class="annot"><span class="annottext">&lt;*&gt; :: forall a b. Stream m a (a -&gt; b) -&gt; Stream m a a -&gt; Stream m a b
</span><a href="../../base/src/GHC.Base.html#%3C%2A%3E"><span class="hs-operator hs-var hs-var hs-var hs-var">(&lt;*&gt;)</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Stream m a (a -&gt; b) -&gt; Stream m a a -&gt; Stream m a b
forall (m :: * -&gt; *) a b. Monad m =&gt; m (a -&gt; b) -&gt; m a -&gt; m b
</span><a href="../../base/src/GHC.Base.html#ap"><span class="hs-identifier hs-var">ap</span></a></span></span></span><span>
</span><span id="line-49"></span><span>
</span><span id="line-50"></span><span id="local-6989586621680774248"><span id="local-6989586621680774249"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621680774079"><span id="local-6989586621680774081"><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774249"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774249"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774248"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-51"></span><span>
</span><span id="line-52"></span><span>  </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span id="local-6989586621680774074"><span class="annot"><span class="annottext">m (Either a (a, Stream m a a))
</span><a href="#local-6989586621680774074"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621680774073"><span class="annot"><span class="annottext">&gt;&gt;= :: forall a b. Stream m a a -&gt; (a -&gt; Stream m a b) -&gt; Stream m a b
</span><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var hs-var hs-var hs-var">&gt;&gt;=</span></a></span></span><span> </span><span id="local-6989586621680774072"><span class="annot"><span class="annottext">a -&gt; Stream m a b
</span><a href="#local-6989586621680774072"><span class="hs-identifier hs-var">k</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">m (Either b (a, Stream m a b)) -&gt; Stream m a b
forall (m :: * -&gt; *) a b.
m (Either b (a, Stream m a b)) -&gt; Stream m a b
</span><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-var">Stream</span></a></span><span> </span><span class="annot"><span class="annottext">(m (Either b (a, Stream m a b)) -&gt; Stream m a b)
-&gt; m (Either b (a, Stream m a b)) -&gt; Stream m a b
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-53"></span><span>                </span><span id="local-6989586621680774071"><span class="annot"><span class="annottext">Either a (a, Stream m a a)
</span><a href="#local-6989586621680774071"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">m (Either a (a, Stream m a a))
</span><a href="#local-6989586621680774074"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-54"></span><span>                </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Either a (a, Stream m a a)
</span><a href="#local-6989586621680774071"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-55"></span><span>                  </span><span class="annot"><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span id="local-6989586621680774070"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774070"><span class="hs-identifier hs-var">b</span></a></span></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Stream m a b -&gt; m (Either b (a, Stream m a b))
forall (m :: * -&gt; *) a b.
Stream m a b -&gt; m (Either b (a, Stream m a b))
</span><a href="GHC.Data.Stream.html#runStream"><span class="hs-identifier hs-var hs-var">runStream</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Stream m a b
</span><a href="#local-6989586621680774072"><span class="hs-identifier hs-var">k</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774070"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-56"></span><span>                  </span><span class="annot"><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680774069"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774069"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680774068"><span class="annot"><span class="annottext">Stream m a a
</span><a href="#local-6989586621680774068"><span class="hs-identifier hs-var">str</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Either b (a, Stream m a b) -&gt; m (Either b (a, Stream m a b))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(a, Stream m a b) -&gt; Either b (a, Stream m a b)
forall a b. b -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-var">Right</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774069"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Stream m a a
</span><a href="#local-6989586621680774068"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a a -&gt; (a -&gt; Stream m a b) -&gt; Stream m a b
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; Stream m a b
</span><a href="#local-6989586621680774072"><span class="hs-identifier hs-var">k</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span></span></span><span>
</span><span id="line-57"></span><span>
</span><span id="line-58"></span><span id="local-6989586621680774209"><span id="local-6989586621680774210"><span class="annot"><a href="GHC.Data.Stream.html#yield"><span class="hs-identifier hs-type">yield</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774210"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680774209"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774210"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774209"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span></span><span>
</span><span id="line-59"></span><span id="yield"><span class="annot"><span class="annottext">yield :: forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; Stream m a ()
</span><a href="GHC.Data.Stream.html#yield"><span class="hs-identifier hs-var hs-var">yield</span></a></span></span><span> </span><span id="local-6989586621680774064"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774064"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">m (Either () (a, Stream m a ())) -&gt; Stream m a ()
forall (m :: * -&gt; *) a b.
m (Either b (a, Stream m a b)) -&gt; Stream m a b
</span><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-var">Stream</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Either () (a, Stream m a ()) -&gt; m (Either () (a, Stream m a ()))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(a, Stream m a ()) -&gt; Either () (a, Stream m a ())
forall a b. b -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-var">Right</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774064"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">() -&gt; Stream m a ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-60"></span><span>
</span><span id="line-61"></span><span id="local-6989586621680774205"><span id="local-6989586621680774206"><span class="annot"><a href="GHC.Data.Stream.html#liftIO"><span class="hs-identifier hs-type">liftIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621680774206"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621680774205"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774206"><span class="hs-identifier hs-type">a</span></a></span></span></span><span>
</span><span id="line-62"></span><span id="liftIO"><span class="annot"><span class="annottext">liftIO :: forall a b. IO a -&gt; Stream IO b a
</span><a href="GHC.Data.Stream.html#liftIO"><span class="hs-identifier hs-var hs-var">liftIO</span></a></span></span><span> </span><span id="local-6989586621680774060"><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621680774060"><span class="hs-identifier hs-var">io</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO (Either a (b, Stream IO b a)) -&gt; Stream IO b a
forall (m :: * -&gt; *) a b.
m (Either b (a, Stream m a b)) -&gt; Stream m a b
</span><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-var">Stream</span></a></span><span> </span><span class="annot"><span class="annottext">(IO (Either a (b, Stream IO b a)) -&gt; Stream IO b a)
-&gt; IO (Either a (b, Stream IO b a)) -&gt; Stream IO b a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">IO a
</span><a href="#local-6989586621680774060"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">IO a
-&gt; (a -&gt; IO (Either a (b, Stream IO b a)))
-&gt; IO (Either a (b, Stream IO b a))
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Either a (b, Stream IO b a) -&gt; IO (Either a (b, Stream IO b a))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(Either a (b, Stream IO b a) -&gt; IO (Either a (b, Stream IO b a)))
-&gt; (a -&gt; Either a (b, Stream IO b a))
-&gt; a
-&gt; IO (Either a (b, Stream IO b a))
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; Either a (b, Stream IO b a)
forall a b. a -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span>
</span><span id="line-63"></span><span>
</span><span id="line-64"></span><span class="hs-comment">-- | Turn a Stream into an ordinary list, by demanding all the elements.</span><span>
</span><span id="line-65"></span><span id="local-6989586621680774198"><span id="local-6989586621680774199"><span class="annot"><a href="GHC.Data.Stream.html#collect"><span class="hs-identifier hs-type">collect</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774199"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774199"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774198"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680774199"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621680774198"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span></span></span><span>
</span><span id="line-66"></span><span id="collect"><span class="annot"><span class="annottext">collect :: forall (m :: * -&gt; *) a. Monad m =&gt; Stream m a () -&gt; m [a]
</span><a href="GHC.Data.Stream.html#collect"><span class="hs-identifier hs-var hs-var">collect</span></a></span></span><span> </span><span id="local-6989586621680774056"><span class="annot"><span class="annottext">Stream m a ()
</span><a href="#local-6989586621680774056"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Stream m a () -&gt; [a] -&gt; m [a]
forall {m :: * -&gt; *} {a}. Monad m =&gt; Stream m a () -&gt; [a] -&gt; m [a]
</span><a href="#local-6989586621680774055"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a ()
</span><a href="#local-6989586621680774056"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-67"></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-68"></span><span>  </span><span id="local-6989586621680774055"><span class="annot"><span class="annottext">go :: Stream m a () -&gt; [a] -&gt; m [a]
</span><a href="#local-6989586621680774055"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621680774051"><span class="annot"><span class="annottext">Stream m a ()
</span><a href="#local-6989586621680774051"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span id="local-6989586621680774050"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621680774050"><span class="hs-identifier hs-var">acc</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-69"></span><span>    </span><span id="local-6989586621680774049"><span class="annot"><span class="annottext">Either () (a, Stream m a ())
</span><a href="#local-6989586621680774049"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Stream m a () -&gt; m (Either () (a, Stream m a ()))
forall (m :: * -&gt; *) a b.
Stream m a b -&gt; m (Either b (a, Stream m a b))
</span><a href="GHC.Data.Stream.html#runStream"><span class="hs-identifier hs-var hs-var">runStream</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a ()
</span><a href="#local-6989586621680774051"><span class="hs-identifier hs-var">str</span></a></span><span>
</span><span id="line-70"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Either () (a, Stream m a ())
</span><a href="#local-6989586621680774049"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-71"></span><span>      </span><span class="annot"><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; m [a]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[a] -&gt; [a]
forall a. [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621680774050"><span class="hs-identifier hs-var">acc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-72"></span><span>      </span><span class="annot"><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680774047"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774047"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680774046"><span class="annot"><span class="annottext">Stream m a ()
</span><a href="#local-6989586621680774046"><span class="hs-identifier hs-var">str'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Stream m a () -&gt; [a] -&gt; m [a]
</span><a href="#local-6989586621680774055"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a ()
</span><a href="#local-6989586621680774046"><span class="hs-identifier hs-var">str'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774047"><span class="hs-identifier hs-var">a</span></a></span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621680774050"><span class="hs-identifier hs-var">acc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-73"></span><span>
</span><span id="line-74"></span><span class="hs-comment">-- | Turn a Stream into an ordinary list, by demanding all the elements.</span><span>
</span><span id="line-75"></span><span id="local-6989586621680774189"><span id="local-6989586621680774190"><span id="local-6989586621680774191"><span class="annot"><a href="GHC.Data.Stream.html#collect_"><span class="hs-identifier hs-type">collect_</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774191"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774191"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774190"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774189"><span class="hs-identifier hs-type">r</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680774191"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621680774190"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621680774189"><span class="hs-identifier hs-type">r</span></a></span><span class="hs-special">)</span></span></span></span><span>
</span><span id="line-76"></span><span id="collect_"><span class="annot"><span class="annottext">collect_ :: forall (m :: * -&gt; *) a r. Monad m =&gt; Stream m a r -&gt; m ([a], r)
</span><a href="GHC.Data.Stream.html#collect_"><span class="hs-identifier hs-var hs-var">collect_</span></a></span></span><span> </span><span id="local-6989586621680774043"><span class="annot"><span class="annottext">Stream m a r
</span><a href="#local-6989586621680774043"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Stream m a r -&gt; [a] -&gt; m ([a], r)
forall {m :: * -&gt; *} {a} {b}.
Monad m =&gt;
Stream m a b -&gt; [a] -&gt; m ([a], b)
</span><a href="#local-6989586621680774042"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a r
</span><a href="#local-6989586621680774043"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-77"></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-78"></span><span>  </span><span id="local-6989586621680774042"><span class="annot"><span class="annottext">go :: Stream m a b -&gt; [a] -&gt; m ([a], b)
</span><a href="#local-6989586621680774042"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621680774038"><span class="annot"><span class="annottext">Stream m a b
</span><a href="#local-6989586621680774038"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span id="local-6989586621680774037"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621680774037"><span class="hs-identifier hs-var">acc</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-79"></span><span>    </span><span id="local-6989586621680774036"><span class="annot"><span class="annottext">Either b (a, Stream m a b)
</span><a href="#local-6989586621680774036"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Stream m a b -&gt; m (Either b (a, Stream m a b))
forall (m :: * -&gt; *) a b.
Stream m a b -&gt; m (Either b (a, Stream m a b))
</span><a href="GHC.Data.Stream.html#runStream"><span class="hs-identifier hs-var hs-var">runStream</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a b
</span><a href="#local-6989586621680774038"><span class="hs-identifier hs-var">str</span></a></span><span>
</span><span id="line-80"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Either b (a, Stream m a b)
</span><a href="#local-6989586621680774036"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-81"></span><span>      </span><span class="annot"><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span id="local-6989586621680774035"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680774035"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">([a], b) -&gt; m ([a], b)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[a] -&gt; [a]
forall a. [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621680774037"><span class="hs-identifier hs-var">acc</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680774035"><span class="hs-identifier hs-var">r</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-82"></span><span>      </span><span class="annot"><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680774034"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774034"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680774033"><span class="annot"><span class="annottext">Stream m a b
</span><a href="#local-6989586621680774033"><span class="hs-identifier hs-var">str'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Stream m a b -&gt; [a] -&gt; m ([a], b)
</span><a href="#local-6989586621680774042"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a b
</span><a href="#local-6989586621680774033"><span class="hs-identifier hs-var">str'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774034"><span class="hs-identifier hs-var">a</span></a></span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621680774037"><span class="hs-identifier hs-var">acc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-83"></span><span>
</span><span id="line-84"></span><span id="local-6989586621680774180"><span id="local-6989586621680774181"><span id="local-6989586621680774182"><span class="annot"><a href="GHC.Data.Stream.html#consume"><span class="hs-identifier hs-type">consume</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774182"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774182"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774181"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774180"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680774181"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680774182"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680774182"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774180"><span class="hs-identifier hs-type">b</span></a></span></span></span></span><span>
</span><span id="line-85"></span><span id="consume"><span class="annot"><span class="annottext">consume :: forall (m :: * -&gt; *) a b.
Monad m =&gt;
Stream m a b -&gt; (a -&gt; m ()) -&gt; m b
</span><a href="GHC.Data.Stream.html#consume"><span class="hs-identifier hs-var hs-var">consume</span></a></span></span><span> </span><span id="local-6989586621680774027"><span class="annot"><span class="annottext">Stream m a b
</span><a href="#local-6989586621680774027"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span id="local-6989586621680774026"><span class="annot"><span class="annottext">a -&gt; m ()
</span><a href="#local-6989586621680774026"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-86"></span><span>    </span><span id="local-6989586621680774025"><span class="annot"><span class="annottext">Either b (a, Stream m a b)
</span><a href="#local-6989586621680774025"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Stream m a b -&gt; m (Either b (a, Stream m a b))
forall (m :: * -&gt; *) a b.
Stream m a b -&gt; m (Either b (a, Stream m a b))
</span><a href="GHC.Data.Stream.html#runStream"><span class="hs-identifier hs-var hs-var">runStream</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a b
</span><a href="#local-6989586621680774027"><span class="hs-identifier hs-var">str</span></a></span><span>
</span><span id="line-87"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Either b (a, Stream m a b)
</span><a href="#local-6989586621680774025"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-88"></span><span>      </span><span class="annot"><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span id="local-6989586621680774024"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680774024"><span class="hs-identifier hs-var">ret</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">b -&gt; m b
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680774024"><span class="hs-identifier hs-var">ret</span></a></span><span>
</span><span id="line-89"></span><span>      </span><span class="annot"><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680774023"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774023"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680774022"><span class="annot"><span class="annottext">Stream m a b
</span><a href="#local-6989586621680774022"><span class="hs-identifier hs-var">str'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-90"></span><span>        </span><span class="annot"><span class="annottext">a -&gt; m ()
</span><a href="#local-6989586621680774026"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774023"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-91"></span><span>        </span><span class="annot"><span class="annottext">Stream m a b -&gt; (a -&gt; m ()) -&gt; m b
forall (m :: * -&gt; *) a b.
Monad m =&gt;
Stream m a b -&gt; (a -&gt; m ()) -&gt; m b
</span><a href="GHC.Data.Stream.html#consume"><span class="hs-identifier hs-var">consume</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a b
</span><a href="#local-6989586621680774022"><span class="hs-identifier hs-var">str'</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; m ()
</span><a href="#local-6989586621680774026"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-92"></span><span>
</span><span id="line-93"></span><span class="hs-comment">-- | Turn a list into a 'Stream', by yielding each element in turn.</span><span>
</span><span id="line-94"></span><span id="local-6989586621680774175"><span id="local-6989586621680774176"><span class="annot"><a href="GHC.Data.Stream.html#fromList"><span class="hs-identifier hs-type">fromList</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774176"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621680774175"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774176"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774175"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span></span><span>
</span><span id="line-95"></span><span id="fromList"><span class="annot"><span class="annottext">fromList :: forall (m :: * -&gt; *) a. Monad m =&gt; [a] -&gt; Stream m a ()
</span><a href="GHC.Data.Stream.html#fromList"><span class="hs-identifier hs-var hs-var">fromList</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(a -&gt; Stream m a ()) -&gt; [a] -&gt; Stream m a ()
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Foldable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m ()
</span><a href="../../base/src/Data.Foldable.html#mapM_"><span class="hs-identifier hs-var">mapM_</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; Stream m a ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; Stream m a ()
</span><a href="GHC.Data.Stream.html#yield"><span class="hs-identifier hs-var">yield</span></a></span><span>
</span><span id="line-96"></span><span>
</span><span id="line-97"></span><span class="hs-comment">-- | Apply a function to each element of a 'Stream', lazily</span><span>
</span><span id="line-98"></span><span id="local-6989586621680774165"><span id="local-6989586621680774166"><span id="local-6989586621680774167"><span id="local-6989586621680774168"><span class="annot"><a href="GHC.Data.Stream.html#map"><span class="hs-identifier hs-type">map</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774168"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680774167"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680774166"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774168"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774167"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774165"><span class="hs-identifier hs-type">x</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774168"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774166"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774165"><span class="hs-identifier hs-type">x</span></a></span></span></span></span></span><span>
</span><span id="line-99"></span><span id="map"><span class="annot"><span class="annottext">map :: forall (m :: * -&gt; *) a b x.
Monad m =&gt;
(a -&gt; b) -&gt; Stream m a x -&gt; Stream m b x
</span><a href="GHC.Data.Stream.html#map"><span class="hs-identifier hs-var hs-var">map</span></a></span></span><span> </span><span id="local-6989586621680774010"><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621680774010"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621680774009"><span class="annot"><span class="annottext">Stream m a x
</span><a href="#local-6989586621680774009"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">m (Either x (b, Stream m b x)) -&gt; Stream m b x
forall (m :: * -&gt; *) a b.
m (Either b (a, Stream m a b)) -&gt; Stream m a b
</span><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-var">Stream</span></a></span><span> </span><span class="annot"><span class="annottext">(m (Either x (b, Stream m b x)) -&gt; Stream m b x)
-&gt; m (Either x (b, Stream m b x)) -&gt; Stream m b x
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-100"></span><span>   </span><span id="local-6989586621680774008"><span class="annot"><span class="annottext">Either x (a, Stream m a x)
</span><a href="#local-6989586621680774008"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Stream m a x -&gt; m (Either x (a, Stream m a x))
forall (m :: * -&gt; *) a b.
Stream m a b -&gt; m (Either b (a, Stream m a b))
</span><a href="GHC.Data.Stream.html#runStream"><span class="hs-identifier hs-var hs-var">runStream</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a x
</span><a href="#local-6989586621680774009"><span class="hs-identifier hs-var">str</span></a></span><span>
</span><span id="line-101"></span><span>   </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Either x (a, Stream m a x)
</span><a href="#local-6989586621680774008"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-102"></span><span>     </span><span class="annot"><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span id="local-6989586621680774007"><span class="annot"><span class="annottext">x
</span><a href="#local-6989586621680774007"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Either x (b, Stream m b x) -&gt; m (Either x (b, Stream m b x))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">x -&gt; Either x (b, Stream m b x)
forall a b. a -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">x
</span><a href="#local-6989586621680774007"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-103"></span><span>     </span><span class="annot"><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680774006"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774006"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680774005"><span class="annot"><span class="annottext">Stream m a x
</span><a href="#local-6989586621680774005"><span class="hs-identifier hs-var">str'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Either x (b, Stream m b x) -&gt; m (Either x (b, Stream m b x))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(b, Stream m b x) -&gt; Either x (b, Stream m b x)
forall a b. b -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-var">Right</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621680774010"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680774006"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">(a -&gt; b) -&gt; Stream m a x -&gt; Stream m b x
forall (m :: * -&gt; *) a b x.
Monad m =&gt;
(a -&gt; b) -&gt; Stream m a x -&gt; Stream m b x
</span><a href="GHC.Data.Stream.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; b
</span><a href="#local-6989586621680774010"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a x
</span><a href="#local-6989586621680774005"><span class="hs-identifier hs-var">str'</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-104"></span><span>
</span><span id="line-105"></span><span class="hs-comment">-- | Apply a monadic operation to each element of a 'Stream', lazily</span><span>
</span><span id="line-106"></span><span id="local-6989586621680774157"><span id="local-6989586621680774158"><span id="local-6989586621680774159"><span id="local-6989586621680774160"><span class="annot"><a href="GHC.Data.Stream.html#mapM"><span class="hs-identifier hs-type">mapM</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774160"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680774159"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680774160"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774158"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774160"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774159"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774157"><span class="hs-identifier hs-type">x</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774160"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774158"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774157"><span class="hs-identifier hs-type">x</span></a></span></span></span></span></span><span>
</span><span id="line-107"></span><span id="mapM"><span class="annot"><span class="annottext">mapM :: forall (m :: * -&gt; *) a b x.
Monad m =&gt;
(a -&gt; m b) -&gt; Stream m a x -&gt; Stream m b x
</span><a href="GHC.Data.Stream.html#mapM"><span class="hs-identifier hs-var hs-var">mapM</span></a></span></span><span> </span><span id="local-6989586621680773998"><span class="annot"><span class="annottext">a -&gt; m b
</span><a href="#local-6989586621680773998"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621680773997"><span class="annot"><span class="annottext">Stream m a x
</span><a href="#local-6989586621680773997"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">m (Either x (b, Stream m b x)) -&gt; Stream m b x
forall (m :: * -&gt; *) a b.
m (Either b (a, Stream m a b)) -&gt; Stream m a b
</span><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-var">Stream</span></a></span><span> </span><span class="annot"><span class="annottext">(m (Either x (b, Stream m b x)) -&gt; Stream m b x)
-&gt; m (Either x (b, Stream m b x)) -&gt; Stream m b x
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-108"></span><span>   </span><span id="local-6989586621680773996"><span class="annot"><span class="annottext">Either x (a, Stream m a x)
</span><a href="#local-6989586621680773996"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Stream m a x -&gt; m (Either x (a, Stream m a x))
forall (m :: * -&gt; *) a b.
Stream m a b -&gt; m (Either b (a, Stream m a b))
</span><a href="GHC.Data.Stream.html#runStream"><span class="hs-identifier hs-var hs-var">runStream</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a x
</span><a href="#local-6989586621680773997"><span class="hs-identifier hs-var">str</span></a></span><span>
</span><span id="line-109"></span><span>   </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Either x (a, Stream m a x)
</span><a href="#local-6989586621680773996"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-110"></span><span>     </span><span class="annot"><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span id="local-6989586621680773995"><span class="annot"><span class="annottext">x
</span><a href="#local-6989586621680773995"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Either x (b, Stream m b x) -&gt; m (Either x (b, Stream m b x))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">x -&gt; Either x (b, Stream m b x)
forall a b. a -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">x
</span><a href="#local-6989586621680773995"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-111"></span><span>     </span><span class="annot"><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680773994"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680773994"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680773993"><span class="annot"><span class="annottext">Stream m a x
</span><a href="#local-6989586621680773993"><span class="hs-identifier hs-var">str'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-112"></span><span>        </span><span id="local-6989586621680773992"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680773992"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">a -&gt; m b
</span><a href="#local-6989586621680773998"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680773994"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-113"></span><span>        </span><span class="annot"><span class="annottext">Either x (b, Stream m b x) -&gt; m (Either x (b, Stream m b x))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(b, Stream m b x) -&gt; Either x (b, Stream m b x)
forall a b. b -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-var">Right</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680773992"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">(a -&gt; m b) -&gt; Stream m a x -&gt; Stream m b x
forall (m :: * -&gt; *) a b x.
Monad m =&gt;
(a -&gt; m b) -&gt; Stream m a x -&gt; Stream m b x
</span><a href="GHC.Data.Stream.html#mapM"><span class="hs-identifier hs-var">mapM</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; m b
</span><a href="#local-6989586621680773998"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a x
</span><a href="#local-6989586621680773993"><span class="hs-identifier hs-var">str'</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-114"></span><span>
</span><span id="line-115"></span><span class="hs-comment">-- | analog of the list-based 'mapAccumL' on Streams.  This is a simple</span><span>
</span><span id="line-116"></span><span class="hs-comment">-- way to map over a Stream while carrying some state around.</span><span>
</span><span id="line-117"></span><span id="local-6989586621680774149"><span id="local-6989586621680774150"><span id="local-6989586621680774151"><span id="local-6989586621680774152"><span class="annot"><a href="GHC.Data.Stream.html#mapAccumL"><span class="hs-identifier hs-type">mapAccumL</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774152"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680774151"><span class="hs-identifier hs-type">c</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680774150"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680774152"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680774151"><span class="hs-identifier hs-type">c</span></a></span><span class="hs-special">,</span><span class="annot"><a href="#local-6989586621680774149"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680774151"><span class="hs-identifier hs-type">c</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774152"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774150"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-118"></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774152"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774149"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774151"><span class="hs-identifier hs-type">c</span></a></span></span></span></span></span><span>
</span><span id="line-119"></span><span id="mapAccumL"><span class="annot"><span class="annottext">mapAccumL :: forall (m :: * -&gt; *) c a b.
Monad m =&gt;
(c -&gt; a -&gt; m (c, b)) -&gt; c -&gt; Stream m a () -&gt; Stream m b c
</span><a href="GHC.Data.Stream.html#mapAccumL"><span class="hs-identifier hs-var hs-var">mapAccumL</span></a></span></span><span> </span><span id="local-6989586621680773985"><span class="annot"><span class="annottext">c -&gt; a -&gt; m (c, b)
</span><a href="#local-6989586621680773985"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621680773984"><span class="annot"><span class="annottext">c
</span><a href="#local-6989586621680773984"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span id="local-6989586621680773983"><span class="annot"><span class="annottext">Stream m a ()
</span><a href="#local-6989586621680773983"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">m (Either c (b, Stream m b c)) -&gt; Stream m b c
forall (m :: * -&gt; *) a b.
m (Either b (a, Stream m a b)) -&gt; Stream m a b
</span><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-var">Stream</span></a></span><span> </span><span class="annot"><span class="annottext">(m (Either c (b, Stream m b c)) -&gt; Stream m b c)
-&gt; m (Either c (b, Stream m b c)) -&gt; Stream m b c
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-120"></span><span>  </span><span id="local-6989586621680773982"><span class="annot"><span class="annottext">Either () (a, Stream m a ())
</span><a href="#local-6989586621680773982"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Stream m a () -&gt; m (Either () (a, Stream m a ()))
forall (m :: * -&gt; *) a b.
Stream m a b -&gt; m (Either b (a, Stream m a b))
</span><a href="GHC.Data.Stream.html#runStream"><span class="hs-identifier hs-var hs-var">runStream</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a ()
</span><a href="#local-6989586621680773983"><span class="hs-identifier hs-var">str</span></a></span><span>
</span><span id="line-121"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Either () (a, Stream m a ())
</span><a href="#local-6989586621680773982"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-122"></span><span>    </span><span class="annot"><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span>  </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Either c (b, Stream m b c) -&gt; m (Either c (b, Stream m b c))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">c -&gt; Either c (b, Stream m b c)
forall a b. a -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">c
</span><a href="#local-6989586621680773984"><span class="hs-identifier hs-var">c</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-123"></span><span>    </span><span class="annot"><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680773981"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680773981"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680773980"><span class="annot"><span class="annottext">Stream m a ()
</span><a href="#local-6989586621680773980"><span class="hs-identifier hs-var">str'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-124"></span><span>      </span><span class="hs-special">(</span><span id="local-6989586621680773979"><span class="annot"><span class="annottext">c
</span><a href="#local-6989586621680773979"><span class="hs-identifier hs-var">c'</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680773978"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680773978"><span class="hs-identifier hs-var">b</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">c -&gt; a -&gt; m (c, b)
</span><a href="#local-6989586621680773985"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">c
</span><a href="#local-6989586621680773984"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680773981"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-125"></span><span>      </span><span class="annot"><span class="annottext">Either c (b, Stream m b c) -&gt; m (Either c (b, Stream m b c))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(b, Stream m b c) -&gt; Either c (b, Stream m b c)
forall a b. b -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-var">Right</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680773978"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">(c -&gt; a -&gt; m (c, b)) -&gt; c -&gt; Stream m a () -&gt; Stream m b c
forall (m :: * -&gt; *) c a b.
Monad m =&gt;
(c -&gt; a -&gt; m (c, b)) -&gt; c -&gt; Stream m a () -&gt; Stream m b c
</span><a href="GHC.Data.Stream.html#mapAccumL"><span class="hs-identifier hs-var">mapAccumL</span></a></span><span> </span><span class="annot"><span class="annottext">c -&gt; a -&gt; m (c, b)
</span><a href="#local-6989586621680773985"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">c
</span><a href="#local-6989586621680773979"><span class="hs-identifier hs-var">c'</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a ()
</span><a href="#local-6989586621680773980"><span class="hs-identifier hs-var">str'</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-126"></span><span>
</span><span id="line-127"></span><span id="local-6989586621680774140"><span id="local-6989586621680774141"><span id="local-6989586621680774142"><span id="local-6989586621680774143"><span id="local-6989586621680774144"><span class="annot"><a href="GHC.Data.Stream.html#mapAccumL_"><span class="hs-identifier hs-type">mapAccumL_</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#Monad"><span class="hs-identifier hs-type">Monad</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774144"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680774143"><span class="hs-identifier hs-type">c</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680774142"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680774144"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680774143"><span class="hs-identifier hs-type">c</span></a></span><span class="hs-special">,</span><span class="annot"><a href="#local-6989586621680774141"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621680774143"><span class="hs-identifier hs-type">c</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774144"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774142"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774140"><span class="hs-identifier hs-type">r</span></a></span><span>
</span><span id="line-128"></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-type">Stream</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774144"><span class="hs-identifier hs-type">m</span></a></span><span> </span><span class="annot"><a href="#local-6989586621680774141"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621680774143"><span class="hs-identifier hs-type">c</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621680774140"><span class="hs-identifier hs-type">r</span></a></span><span class="hs-special">)</span></span></span></span></span></span><span>
</span><span id="line-129"></span><span id="mapAccumL_"><span class="annot"><span class="annottext">mapAccumL_ :: forall (m :: * -&gt; *) c a b r.
Monad m =&gt;
(c -&gt; a -&gt; m (c, b)) -&gt; c -&gt; Stream m a r -&gt; Stream m b (c, r)
</span><a href="GHC.Data.Stream.html#mapAccumL_"><span class="hs-identifier hs-var hs-var">mapAccumL_</span></a></span></span><span> </span><span id="local-6989586621680773971"><span class="annot"><span class="annottext">c -&gt; a -&gt; m (c, b)
</span><a href="#local-6989586621680773971"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span id="local-6989586621680773970"><span class="annot"><span class="annottext">c
</span><a href="#local-6989586621680773970"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span id="local-6989586621680773969"><span class="annot"><span class="annottext">Stream m a r
</span><a href="#local-6989586621680773969"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">m (Either (c, r) (b, Stream m b (c, r))) -&gt; Stream m b (c, r)
forall (m :: * -&gt; *) a b.
m (Either b (a, Stream m a b)) -&gt; Stream m a b
</span><a href="GHC.Data.Stream.html#Stream"><span class="hs-identifier hs-var">Stream</span></a></span><span> </span><span class="annot"><span class="annottext">(m (Either (c, r) (b, Stream m b (c, r))) -&gt; Stream m b (c, r))
-&gt; m (Either (c, r) (b, Stream m b (c, r))) -&gt; Stream m b (c, r)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-130"></span><span>  </span><span id="local-6989586621680773968"><span class="annot"><span class="annottext">Either r (a, Stream m a r)
</span><a href="#local-6989586621680773968"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Stream m a r -&gt; m (Either r (a, Stream m a r))
forall (m :: * -&gt; *) a b.
Stream m a b -&gt; m (Either b (a, Stream m a b))
</span><a href="GHC.Data.Stream.html#runStream"><span class="hs-identifier hs-var hs-var">runStream</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a r
</span><a href="#local-6989586621680773969"><span class="hs-identifier hs-var">str</span></a></span><span>
</span><span id="line-131"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Either r (a, Stream m a r)
</span><a href="#local-6989586621680773968"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-132"></span><span>    </span><span class="annot"><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span>  </span><span id="local-6989586621680773967"><span class="annot"><span class="annottext">r
</span><a href="#local-6989586621680773967"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Either (c, r) (b, Stream m b (c, r))
-&gt; m (Either (c, r) (b, Stream m b (c, r)))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(c, r) -&gt; Either (c, r) (b, Stream m b (c, r))
forall a b. a -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">c
</span><a href="#local-6989586621680773970"><span class="hs-identifier hs-var">c</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">r
</span><a href="#local-6989586621680773967"><span class="hs-identifier hs-var">r</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-133"></span><span>    </span><span class="annot"><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621680773966"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680773966"><span class="hs-identifier hs-var">a</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621680773965"><span class="annot"><span class="annottext">Stream m a r
</span><a href="#local-6989586621680773965"><span class="hs-identifier hs-var">str'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-134"></span><span>      </span><span class="hs-special">(</span><span id="local-6989586621680773964"><span class="annot"><span class="annottext">c
</span><a href="#local-6989586621680773964"><span class="hs-identifier hs-var">c'</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621680773963"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680773963"><span class="hs-identifier hs-var">b</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">c -&gt; a -&gt; m (c, b)
</span><a href="#local-6989586621680773971"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">c
</span><a href="#local-6989586621680773970"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621680773966"><span class="hs-identifier hs-var">a</span></a></span><span>
</span><span id="line-135"></span><span>      </span><span class="annot"><span class="annottext">Either (c, r) (b, Stream m b (c, r))
-&gt; m (Either (c, r) (b, Stream m b (c, r)))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(b, Stream m b (c, r)) -&gt; Either (c, r) (b, Stream m b (c, r))
forall a b. b -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-var">Right</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621680773963"><span class="hs-identifier hs-var">b</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">(c -&gt; a -&gt; m (c, b)) -&gt; c -&gt; Stream m a r -&gt; Stream m b (c, r)
forall (m :: * -&gt; *) c a b r.
Monad m =&gt;
(c -&gt; a -&gt; m (c, b)) -&gt; c -&gt; Stream m a r -&gt; Stream m b (c, r)
</span><a href="GHC.Data.Stream.html#mapAccumL_"><span class="hs-identifier hs-var">mapAccumL_</span></a></span><span> </span><span class="annot"><span class="annottext">c -&gt; a -&gt; m (c, b)
</span><a href="#local-6989586621680773971"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">c
</span><a href="#local-6989586621680773964"><span class="hs-identifier hs-var">c'</span></a></span><span> </span><span class="annot"><span class="annottext">Stream m a r
</span><a href="#local-6989586621680773965"><span class="hs-identifier hs-var">str'</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-136"></span></pre></body></html>